package com.yuncommunity.bigtime;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_main);

        final TextView time = findViewById(R.id.time);
        final TextView date = findViewById(R.id.date);

        final SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
        final SimpleDateFormat formatDate = new SimpleDateFormat("yyyy年MM月dd日 E", Locale.getDefault());
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Date now = new Date();
                        time.setText(formatTime.format(now));
                        date.setText(formatDate.format(now));
                    }
                });
            }
        }, 1000, 1000);
    }
}
